/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skelbkim;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

/**
 *
 * @author laimis
 */
public class SkelbimaiNet extends SeleneseTestCase {

    public void setUp() throws Exception {
        setUp("http://www.skelbimai.net/", "*firefox");
    }

    public void newNotation(String noticeText, String phone, String name, String noticeTitle, String email) throws Exception {
        selenium.open("/");
        selenium.click("link=Įdėti skelbimą");
        if (isPageLoude()) {
            selenium.click("link=Klaipėda");
            selenium.waitForPageToLoad("30000");
            selenium.click("//td[@id='content']/ul/li[10]/a");
            selenium.waitForPageToLoad("30000");
            selenium.click("//td[@id='content']/ul/li[9]/a");
            selenium.waitForPageToLoad("30000");
            selenium.type("adtitle", noticeTitle);
            selenium.type("addesc", noticeText);
            selenium.type("email", email);
            selenium.type("x[1]", phone);
            selenium.click("agree");
            selenium.click("//button[@type='submit']");
        }
        selenium.stop();
    }

    private boolean isPageLoude() {
        boolean result = true;
        while (!selenium.isElementPresent("//table/tbody/tr[2]/td[2]/table[2]/tbody/tr/td/ul/li[15]/a")) {
            selenium.waitForPageToLoad("5000");
        }
        return result;
    }
}

